package cn.njxzc.basicclass;

import java.math.BigDecimal;
import java.util.Scanner;

import com.sun.org.apache.bcel.internal.generic.NEW;

/**
 * *
 * 
 * @Program Name : JavaProgram.basicclass.MyAlgorithm.java
 * @Written by : Roy Xu
 * @Creation Date : Mar 11, 2017 10:13:00 AM
 * @version : v1.00
 * @Description :
 * @ModificationHistory Who When What -------- ----------
 *                      ------------------------------------------------ Roy Xu
 *                      Mar 11, 201710:13:00 AM TODO
 ** 
 */
public class MyAlgorithm {
	/**
	 * 
	 * @Enclosing_Method : getFactorial
	 * @Written by : Roy Xu
	 * @Creation Date : Mar 11, 2017 10:12:47 AM
	 * @version : v1.00
	 * @Description :
	 * 
	 * @param n:factorial 
	 * @param num:algorithm select
	 * @return
	 * 
	 */
	public static BigDecimal getFactorial(int n, int num) {
		BigDecimal result = new BigDecimal(1);
		BigDecimal a;
		switch (num) {
		case 1:// From the beginning of 1,multiplied by N, achieve n
			for (int i = 2; i <= n; i++) {
				a = new BigDecimal(i);// change i to BigDecimal
				result = result.multiply(a);//
			}

			break;
		case 2:// Using recursive implementation: F (n) =n*f (n-1), f (1) =1,
				// recursive multiplication, so as to achieve n!
			a = new BigDecimal(n);
			if (a.equals(new BigDecimal(1))) {
				break;
			} else {
				return a.multiply(getFactorial(a.intValue() - 1, 2));
			}
		}

		return result;

	}

	public static void main(String[] arguments) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		System.out.println(a + "!=" + getFactorial(a, 1));
		System.out.println(a + "!=" + getFactorial(a, 2));
	}
}
